//
//  UIButton+Extension.swift
//  WeiBoDemo
//
//  Created by China Dragon on 2023/8/24.
//

import UIKit
//抽取便利 构造函数
extension UIButton{
    //便利构造函数
    convenience init(imageName: String, backImageName: String){
       self.init()
        //调用默认的构造函数是 自定义的按钮
        // _highlighted 需要 ui设计师和 开发人员约定好
        setImage(UIImage(named: imageName), for: UIControl.State.normal)
        setImage(UIImage(named: imageName + "_highlighted"), for: UIControl.State.highlighted)
        setBackgroundImage(UIImage(named: backImageName), for: UIControl.State.normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), for: UIControl.State.highlighted)
        
        //会根据背景图片大小调整尺寸
        sizeToFit()
    }
    
    
    convenience init(title: String, color: UIColor, imageName: String){
        self.init()

        setTitle(title, for: UIControl.State.normal)
        setTitleColor(color, for: UIControl.State.normal)
        setBackgroundImage(UIImage(named: imageName), for: UIControl.State.normal)
        
    }
}
